package com.wendal.java.happydog;


import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.wendal.java.happydog.bean.PetBean;
import com.wendal.java.happydog.bean.UserBean;

public class Toolkit {

	public static void parseFriends(HappyDogConfig config,String data){
		JSONObject object = JSONObject.fromObject(data);
		if(object.getBoolean("result") == true){
			config.getContent().users.clear();
			config.getContent().pets.clear();
			JSONObject friends = object.getJSONObject("friends");
			String friend_id;
			for (Object friend_ : friends.names()) {
				friend_id = String.valueOf(friend_);
				config.getContent().users.put(friend_id,new UserBean(friends.getJSONObject(friend_id)));
			}
			JSONArray pets = object.getJSONArray("pets");
			for (Object object2 : pets) {
				PetBean petBean = new PetBean((JSONObject) object2);
				config.getContent().pets.add(petBean);
			}
		}
	}
	
	public static final Map<String, String> addKeyValue(Map<String, String> map , String key, String value){
		if(map == null) map = new HashMap<String, String>();
		map.put(key, value);
		return map;
	}
	
}
